from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification, SPU
from meiduo_admin.serializers.sepecs import SPUSpecificationSerializer, SPUSerializer
from meiduo_admin.utils import PageNum

# 规格表的增删查改

class SpecView(ModelViewSet):

    # 指定序列化器
    serializer_class = SPUSpecificationSerializer
    # 指定数据的查询集
    queryset = SPUSpecification.objects.all()
    # 指定特权
    permission_classes = [IsAdminUser]
    # 指定分页器
    pagination_class = PageNum

    # 获取spu信息
    def simple(self,request):
        # 获取所有spu信息
        spus = SPU.objects.all()
        # 返回spu数据
        ser = SPUSerializer(spus,many=True)
        return Response(ser.data)